package com.example.rzprogram;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.base.BaseActivity;
import com.example.network.ProtocolService;
import com.example.utils.MethodUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

public class RegisterActivity extends BaseActivity {
	private String userName,passWord,phone,Email;
	@ViewInject(R.id.user_register_edit)
	private EditText editZhanghao;
	@ViewInject(R.id.user_passeword_register_edit)
	private EditText editPasward;
	@ViewInject(R.id.user_passeword_edit)
	private EditText editPasward2;
	@ViewInject(R.id.user_phone_edit)
	private EditText editPhone;
	@ViewInject(R.id.user_email_edit)
	private EditText editEmail;
	@ViewInject(R.id.img)
	private ImageView image;
	@ViewInject(R.id.btn_register)
	private Button btn_register;
	@ViewInject(R.id.come_back)
	private ImageButton btn_back;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_register_layout);
		ViewUtils.inject(this);
	}

	@OnClick({R.id.img, R.id.btn_register ,R.id.come_back})
	public void onCliecks(View v) {
		switch (v.getId()) {
		case R.id.img:
			//点击更换头像
			break;
		case R.id.btn_register:
			userName = editZhanghao.getText().toString().trim();
			phone = editZhanghao.getText().toString().trim();
			passWord = editPasward.getText().toString().trim();
			Email = editEmail.getText().toString().trim();
			if (MethodUtils.isEmpty(phone)) {
				startAnimation(editZhanghao);
			} else {
				if (MethodUtils.isEmpty(passWord)) {
					startAnimation(editPasward);
				} else {
					// 启动请求进行注册
					ProtocolService.register(MethodUtils.getIMEI(getApplicationContext()) ,
							userName, passWord, Email ,phone,new RequestCallBack<String>() {
						@Override
						public void onSuccess(ResponseInfo<String> arg0) {
							//进行回调解析
							System.out.println(arg0.result);
							Toast.makeText(getApplicationContext(), arg0.result, Toast.LENGTH_SHORT).show();
							Intent intent = new Intent(RegisterActivity.this,LoginActivity.class);
							startActivity(intent);
						}
						
						@Override
						public void onFailure(HttpException arg0, String arg1) {
							//回调失败
							Toast.makeText(getApplicationContext(), "注册失败", Toast.LENGTH_SHORT).show();
						}
					});
				}
			}
			break;
		case R.id.come_back:
			RegisterActivity.this.finish();
		}

	}

}
